from concurrent.futures import ThreadPoolExecutor
import execjs
import requests

def get_info():
    infoList = []
    for line in open('./music.txt', 'r', encoding='utf-8').readlines():
        item = {}
        lineSplit = line.split('\t')
        item['id'] = lineSplit[0]
        item['title'] = lineSplit[-1].strip()
        infoList.append(item)
    return infoList
def js_code(id):
    with open('网易歌单评论.js', 'r', encoding='utf-8') as f:
        js_file = execjs.compile(f.read()).call('params',str(id))
    return  js_file

def comment(num):
    headers = {
        "authority": "music.163.com",
        "accept": "*/*",
        "accept-language": "zh-CN,zh;q=0.9",
        "cache-control": "no-cache",
        "content-type": "application/x-www-form-urlencoded",
        "origin": "https://music.163.com",
        "pragma": "no-cache",
        "referer": "https://music.163.com/playlist?id=26467411",
        "sec-ch-ua": "^\\^Chromium^^;v=^\\^118^^, ^\\^Microsoft",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "^\\^Windows^^",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-origin",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.76"
    }
    cookies = {
        "ntes_utid": "tid._.LvznCOU0WltFVgQURQOF3tC6tVPIVCaF._.0",
        "NMTID": "00OFu2QKyOvy-EbFEBrvTvQ-GxlgbYAAAGLkBWaSA",
        "_iuqxldmzr_": "32",
        "_ntes_nnid": "38a2df508b904bbb5fcbdc97f7d29d85,1698929417368",
        "_ntes_nuid": "38a2df508b904bbb5fcbdc97f7d29d85",
        "WEVNSM": "1.0.0",
        "WNMCID": "nibkyy.1698929419682.01.0",
        "WM_NI": "GoMFgYzDYxxW4xONyanTx8ecuF^%^2BfI48WkUoZfeWcvQ1tATP49hBQkW7DJ4Ip^%^2FUtXlL3QjDkIwVPyQK9Zjm8ML7w5cH6Amhi^%^2BPI^%^2F5cpeQN0^%^2Bhob12^%^2BvZ7kg7z2MLXZiaqRFY^%^3D",
        "WM_NIKE": "9ca17ae2e6ffcda170e2e6eeaebc4aa1bf8e8bf65fb38e8eb6d55b979f9f87c172fb979bb3fc45bce9a28fd92af0fea7c3b92a85b183a7e653ba9c9799fb5df8a881affc6bae8cb8d9e869b79ae587cc40fc89a5b6ee52a6bb9984f55bf3ac8fb5d340fbb88eb2ea5df59c86d5cc7ced8bbcb9ef48f18fa6a5ea43b58aa09ad441fb86a68ebb4790e9b9d6e244f69fa389ec219497e1d6e27ca78f82d1aa64adbeffd3aa7e9ae9a588b672f29384b9d963a3af9ea7dc37e2a3",
        "WM_TID": "l34D4XVmW4tAFBBVAEPUn4YBQzekvniJ",
        "sDeviceId": "YD-9IwILyg^%^2Fbz1BEkEBQBbExpxp20iblHl1",
        "JSESSIONID-WYYY": "l^%^2FoYyfrsPIdH^%^2BqgnbVtgweA24WDgOkVTaVlZThX8^%^2F84^%^2BW5w5JWHRdBJTDMMGMFTESOaHhjUshHaiBRkC3BSbjjse^%^2FKB^%^5CaXUhaICz^%^2BBOUnOIi6qi0psqJGW7uXP1QHsHDlC^%^2FKkFAjb^%^2BzK^%^5CZYWqy1hP1NjbVUpFTkelPbOTKKuGmf56I1x^%^3A1698933759221"
    }
    url = "https://music.163.com/weapi/comment/resource/comments/get"
    params = {
        "csrf_token": ""
    }
    response = requests.post(url, headers=headers, cookies=cookies, params=params, data=js_code(infoList[num]['id']))

    print('-------------------------------------------------------------------------------------')
    print('歌单标题为：',infoList[num]['title'])
    print('评论：',response.text)
    print('-----------------------------------------结束--------------------------------------------')

if __name__ == '__main__':
    infoList = get_info()
    with ThreadPoolExecutor(6) as pool:
        pool.map(comment, [i for i in range(len(infoList))])